package io.inputStram;

import org.junit.jupiter.api.Test;

import java.io.FileInputStream;
import java.io.InputStreamReader;

public class StuInputStream {
    @Test
    public void test01() throws Exception {
        String path = "f:\\重头来过\\javaio\\hello.txt";
//        File file = new File(path);
//        FileInputStream fileInputStream = new FileInputStream(file);

        FileInputStream fileInputStream = new FileInputStream(path);
        //设置字符集读取中文
        InputStreamReader inputStreamReader = new InputStreamReader(fileInputStream, "UTF-8");
        int read = 0;
        while ((read = inputStreamReader.read())!= -1) {
            System.out.print((char) read);
        }
        inputStreamReader.close();
        fileInputStream.close();
    }

    @Test
    public void test02() throws Exception {
        String path = "f:\\重头来过\\javaio\\hello.txt";
        FileInputStream fileInputStream = new FileInputStream(path);
        byte[] bytes = new byte[1024];

        //如果读取正常
        int len = 0;
        len = fileInputStream.read(bytes);
        System.out.println(new String(bytes,0,len));

        fileInputStream.close();
    }
}
